package com.example.allshengmedical.experimentanalyze.activity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import android.R.integer;
import android.app.Activity;
import android.os.Environment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.allsheng.dataprocess.AutoBaseline;
import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.base.BaseFragment;
import com.example.allshengmedical.experimentanalyze.activity.CtFragment.CallBackValue;
import com.example.allshengmedical.experimentanalyze.bean.AdvancedSettingBean;
import com.example.allshengmedical.experimentanalyze.bean.CtSettingBean;
import com.example.allshengmedical.experimentnew.bean.LayoutTableBean;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.experimentrun.activity.AmplifucationActivity;
import com.example.allshengmedical.util.ArrayListRemoveRepitionUtil;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.github.mikephil.charting.data.Entry;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


/**
 * 分析中参数设置中的一个界面
 * @author Administrator
 *
 */
public class AdvancedFragment extends BaseFragment {
	ListView advance_list;
	AdvanceAdapter adapter;
	TextView show_position;
	CheckBox pop_threshold_check;
	CheckBox pop_baseline_check;
	TextView pop_start_add, pop_start_reduce, pop_end_add, pop_end_reduce;
	TextView pop_start_edit, pop_end_edit, confirmBtn;
	RelativeLayout pop_rel;

	// 数据
	String folderName;
	String fileName;
	private String appFilePath = Environment.getExternalStorageDirectory()
			+ "/" + "AllShengMedical";
	StringBuffer contextString = new StringBuffer();

	// 基因盘数据
	public List<HashMap<String, Object>> dataSourceListBlock1 = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlock2 = new ArrayList<HashMap<String, Object>>();
	// 基因盘数据
	public ArrayList<LayoutTableBean> activityLayoutTableBeans;

	// public List<HashMap<String, Object>> dataSourceListBlockToShow = new
	// ArrayList<HashMap<String, Object>>();

	// 本页面的数据
	ArrayList<AdvancedSettingBean> advancedSettingBeans = new ArrayList<AdvancedSettingBean>();
	ArrayList<AdvancedSettingBean> oldAdvancedSettingBeans = new ArrayList<AdvancedSettingBean>();

	ArrayList<CtSettingBean> ctSettingBeans = new ArrayList<CtSettingBean>();

	// 上半部
	private ArrayList<MethodBean> activityMethodBeans = new ArrayList<MethodBean>();
	// 重复次数
	private int repititions;

	// 接口huidiao
	CallBackValue callBackValue;

	private AutoBaseline autoBaseline = new AutoBaseline();

	/**
	 * fragment与activity产生关联是 回调这个方法
	 */
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		// 当前fragment从activity重写了回调接口 得到接口的实例化对象
		callBackValue = (CallBackValue) getActivity();
	}

	@Override
	public int getlayout() {
		return R.layout.fragment_advanced;
	}

	@Override
	protected void initView() {

		getInfo();
		getDragView();
		getLayoutone();
		getActivityBeans();
		View view = LayoutInflater.from(getActivity()).inflate(
				R.layout.item_ct_fragment_head, null);
		TextView well_tv = (TextView) view.findViewById(R.id.well_tv);
		well_tv.setVisibility(view.VISIBLE);
		advance_list.addHeaderView(view);
		// 去除一样的空的
		removenull();

		// 给activity发送传值
		callBackValue.SendMessageValue(advancedSettingBeans);
		adapter = new AdvanceAdapter(advancedSettingBeans);
		advance_list.setAdapter(adapter);

		confirmBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// if(pop_threshold_check.isChecked()){
				// // sdas
				//
				// }
				//
				// advancedSettingBeans
				
				if (Integer.parseInt(pop_start_edit.getText().toString()) > Integer
						.parseInt(pop_end_edit.getText().toString())) {
					
					ByAlert.alert(getActivity().getString(R.string.advance_startend));
					return;
				}
				
				for (AdvancedSettingBean bean : advancedSettingBeans) {
					if (bean.getSelected()) {
						bean.setUseCTSetingBoo(pop_threshold_check.isChecked());
						// 点上就受上个页面影响
						if (pop_threshold_check.isChecked()) {
							for (CtSettingBean ctSettingBean : ctSettingBeans) {
								if (bean.getTargetName().equals(
										ctSettingBean.getTargetName())) {
									if (ctSettingBean.isAutoBaseLine()) {
										double[] pY = new double[repititions];
										int index3 = 0;

										// 获取自动的值
										if (bean.getWell().contains("A")) {
											// activityLayoutTableBeans
											// .get(Integer.parseInt(bean
											// .getWell()
											// .substring(1, 2)));
											for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
												if (bean.getTargetName()
														.equals(layoutTableBean
																.getTarget())) {
													// layoutTableBean.getAisle()

													for (Entry entry : AnalyzeAmplificationplotActivity
															.getInstence().dataListArrayList
															.get(Integer
																	.parseInt(bean
																			.getWell()
																			.substring(
																					1,
																					2)))
															.get(layoutTableBean
																	.getAisle())
															.getYVals()) {
														pY[index3] = entry
																.getVal();
														index3++;
													}

													bean.setBaselineStart(autoBaseline
															.getBaselineStart(
																	pY,
																	repititions)
															+ "");
													bean.setBaselineEndString(autoBaseline
															.getBaselineEnd(pY,
																	repititions)
															+ "");
													
												}
											}

										} else if (bean.getWell().contains("B")) {
											for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
												if (bean.getTargetName()
														.equals(layoutTableBean
																.getTarget())) {
													// layoutTableBean.getAisle()

													for (Entry entry : AnalyzeAmplificationplotActivity
															.getInstence().dataListArrayList
															.get(Integer
																	.parseInt(bean
																			.getWell()
																			.substring(
																					1,
																					2)) + 8)
															.get(layoutTableBean
																	.getAisle())
															.getYVals()) {
														pY[index3] = entry
																.getVal();
														index3++;
													}

													bean.setBaselineStart(autoBaseline
															.getBaselineStart(
																	pY,
																	repititions)
															+ "");
													bean.setBaselineEndString(autoBaseline
															.getBaselineEnd(pY,
																	repititions)
															+ "");
												}
											}

										} else if (bean.getWell().contains("C")) {
											for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
												if (bean.getTargetName()
														.equals(layoutTableBean
																.getTarget())) {
													// layoutTableBean.getAisle()

													for (Entry entry : AnalyzeAmplificationplotActivity
															.getInstence().dataListArrayList
															.get(Integer
																	.parseInt(bean
																			.getWell()
																			.substring(
																					1,
																					2)) + 16)
															.get(layoutTableBean
																	.getAisle())
															.getYVals()) {
														pY[index3] = entry
																.getVal();
														index3++;
													}

													bean.setBaselineStart(autoBaseline
															.getBaselineStart(
																	pY,
																	repititions)
															+ "");
													bean.setBaselineEndString(autoBaseline
															.getBaselineEnd(pY,
																	repititions)
															+ "");
												}
											}

										} else if (bean.getWell().contains("D")) {
											for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
												if (bean.getTargetName()
														.equals(layoutTableBean
																.getTarget())) {
													// layoutTableBean.getAisle()

													for (Entry entry : AnalyzeAmplificationplotActivity
															.getInstence().dataListArrayList
															.get(Integer
																	.parseInt(bean
																			.getWell()
																			.substring(
																					1,
																					2)) + 24)
															.get(layoutTableBean
																	.getAisle())
															.getYVals()) {
														pY[index3] = entry
																.getVal();
														index3++;
													}

													bean.setBaselineStart(autoBaseline
															.getBaselineStart(
																	pY,
																	repititions)
															+ "");
													bean.setBaselineEndString(autoBaseline
															.getBaselineEnd(pY,
																	repititions)
															+ "");
												}
											}
										}

									} else {
										// 不是auto取抽ct里面的

										bean.setBaselineStart(ctSettingBean
												.getBaselineStart() + "");
										bean.setBaselineEndString(ctSettingBean
												.getBaselineEnd() + "");
									}
								}
							}
						} else {
							// 看下面的选择
							if (pop_baseline_check.isChecked()) {

								double[] pY = new double[repititions];
								int index3 = 0;

								// 获取自动的值
								if (bean.getWell().contains("A")) {
									// activityLayoutTableBeans
									// .get(Integer.parseInt(bean
									// .getWell()
									// .substring(1, 2)));
									for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
										if (bean.getTargetName().equals(
												layoutTableBean.getTarget())) {
											// layoutTableBean.getAisle()

											for (Entry entry : AnalyzeAmplificationplotActivity
													.getInstence().dataListArrayList
													.get(Integer.parseInt(bean
															.getWell()
															.substring(1, 2)))
													.get(layoutTableBean
															.getAisle())
													.getYVals()) {
												pY[index3] = entry.getVal();
												index3++;
											}

											bean.setBaselineStart(autoBaseline
													.getBaselineStart(pY,
															repititions)
													+ "");
											bean.setBaselineEndString(autoBaseline
													.getBaselineEnd(pY,
															repititions)
													+ "");
										}
									}

								} else if (bean.getWell().contains("B")) {
									for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
										if (bean.getTargetName().equals(
												layoutTableBean.getTarget())) {
											// layoutTableBean.getAisle()

											for (Entry entry : AnalyzeAmplificationplotActivity
													.getInstence().dataListArrayList
													.get(Integer.parseInt(bean
															.getWell()
															.substring(1, 2)) + 8)
													.get(layoutTableBean
															.getAisle())
													.getYVals()) {
												pY[index3] = entry.getVal();
												index3++;
											}

											bean.setBaselineStart(autoBaseline
													.getBaselineStart(pY,
															repititions)
													+ "");
											bean.setBaselineEndString(autoBaseline
													.getBaselineEnd(pY,
															repititions)
													+ "");
										}
									}

								} else if (bean.getWell().contains("C")) {
									for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
										if (bean.getTargetName().equals(
												layoutTableBean.getTarget())) {
											// layoutTableBean.getAisle()

											for (Entry entry : AnalyzeAmplificationplotActivity
													.getInstence().dataListArrayList
													.get(Integer.parseInt(bean
															.getWell()
															.substring(1, 2)) + 16)
													.get(layoutTableBean
															.getAisle())
													.getYVals()) {
												pY[index3] = entry.getVal();
												index3++;
											}

											bean.setBaselineStart(autoBaseline
													.getBaselineStart(pY,
															repititions)
													+ "");
											bean.setBaselineEndString(autoBaseline
													.getBaselineEnd(pY,
															repititions)
													+ "");
										}
									}

								} else if (bean.getWell().contains("D")) {
									for (LayoutTableBean layoutTableBean : activityLayoutTableBeans) {
										if (bean.getTargetName().equals(
												layoutTableBean.getTarget())) {
											// layoutTableBean.getAisle()

											for (Entry entry : AnalyzeAmplificationplotActivity
													.getInstence().dataListArrayList
													.get(Integer.parseInt(bean
															.getWell()
															.substring(1, 2)) + 24)
													.get(layoutTableBean
															.getAisle())
													.getYVals()) {
												pY[index3] = entry.getVal();
												index3++;
											}

											bean.setBaselineStart(autoBaseline
													.getBaselineStart(pY,
															repititions)
													+ "");
											bean.setBaselineEndString(autoBaseline
													.getBaselineEnd(pY,
															repititions)
													+ "");
										}
									}
								}

							} else {
								bean.setBaselineStart(pop_start_edit.getText()
										+ "");
								bean.setBaselineEndString(pop_end_edit
										.getText() + "");
							}
						}
						bean.setAutoBaselineBoolean(pop_baseline_check
								.isChecked());
						if (pop_baseline_check.isChecked()) {
							bean.setBaseLine("AUTO");
						} else {
							bean.setBaseLine("Manual");
						}
//						bean.setBaselineStart(pop_start_edit.getText() + "");
//						bean.setBaselineEndString(pop_end_edit.getText() + "");
						adapter.notifyDataSetChanged();
					}
				}

				adapter.notifyDataSetChanged();
				// 给activity发送传值
				callBackValue.SendMessageValue(advancedSettingBeans);
				ByAlert.alert(getActivity().getString(R.string.advance_sure));
			}
		});
		// advance_list.setOnItemClickListener(new OnItemClickListener() {
		//
		// @Override
		// public void onItemClick(AdapterView<?> parent, View view,
		// int position, long id) {
		// // ByAlert.alert("aaa"+position);
		//
		// }
		// });

		// pop_threshold_check.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// for (int i = 0; i < advancedSettingBeans.size(); i++) {
		// if (advancedSettingBeans.get(i).getSelected()) {
		// advancedSettingBeans.get(i).
		// }
		// }
		//
		// }
		// });

	}

	private void removenull() {
		// ArrayList<Integer> arraysArrayList = new ArrayList<Integer>();
		HashSet<AdvancedSettingBean> advancedSettingSets = new HashSet<AdvancedSettingBean>();
		for (int i = 0; i < advancedSettingBeans.size(); i++) {
			if (TextUtils.isEmpty(advancedSettingBeans.get(i).getTargetName())
					|| advancedSettingBeans.get(i).getTargetName() == null) {
				for (int j = i + 1; j < advancedSettingBeans.size(); j++) {
					if (i != j) {
						if (advancedSettingBeans.get(i).getWell()
								.equals(advancedSettingBeans.get(j).getWell())) {
							advancedSettingSets
									.add(advancedSettingBeans.get(i));
						}
					}
				}
			}

		}
		for (AdvancedSettingBean adv : advancedSettingSets) {
			advancedSettingBeans.remove(adv);
		}
		if (advancedSettingBeans.size() > 0) {
			advancedSettingBeans.get(0).setSelected(true);
		}

	}

	private void getActivityBeans() {

		advancedSettingBeans = new ArrayList<AdvancedSettingBean>();
		ctSettingBeans = ((ParameterSettingActivity) getActivity()).ctSettingBeans;
		// for (int i = 0; i < 32; i++) {
		// if (i < 16) {
		// // list1
		// int index = i + 1;
		//
		// if (index <= 8) {
		// for (CtSettingBean bean : ctSettingBeans) {
		// boolean boo = false;
		// if (getTargetName(
		// (String) dataSourceListBlock1.get(i).get(
		// "item_image")).equals(
		// bean.getTargetName())) {
		// boo = true;
		// if (bean.isUseDaultSetting()) {
		//
		// if (((ParameterSettingActivity) getActivity()).defaultBaselineBoo) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "A" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "A" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "Manual",
		// ((ParameterSettingActivity) getActivity()).defaultStart,
		// ((ParameterSettingActivity) getActivity()).defaultEnd));
		// }
		//
		// } else {
		// if (bean.isAutoBaseLine()) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "A" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "A" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "Manual",
		// bean.getBaselineStart(),
		// bean.getBaselineEnd()));
		// }
		// }
		//
		// } else {
		// if ("".equals(getTargetName((String) dataSourceListBlock1
		// .get(i).get("item_image")))) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "A" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i).get(
		// "item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// }
		// }
		//
		// }
		//
		// } else {
		// index = index - 8;
		// for (CtSettingBean bean : ctSettingBeans) {
		// boolean boo = false;
		// if (getTargetName(
		// (String) dataSourceListBlock1.get(i).get(
		// "item_image")).equals(
		// bean.getTargetName())) {
		// boo = true;
		// if (bean.isUseDaultSetting()) {
		//
		// if (((ParameterSettingActivity) getActivity()).defaultBaselineBoo) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "B" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "B" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "Manual",
		// ((ParameterSettingActivity) getActivity()).defaultStart,
		// ((ParameterSettingActivity) getActivity()).defaultEnd));
		// }
		//
		// } else {
		// if (bean.isAutoBaseLine()) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "B" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "B" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i)
		// .get("item_image")),
		// "Manual",
		// bean.getBaselineStart(),
		// bean.getBaselineEnd()));
		// }
		// }
		//
		// } else {
		// if ("".equals(getTargetName((String) dataSourceListBlock1
		// .get(i).get("item_image")))) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "B" + index,
		// getTargetName((String) dataSourceListBlock1
		// .get(i).get(
		// "item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// }
		// }
		//
		// }
		// }
		//
		// } else {
		// // list2
		// int index = i + 1;
		// if (index <= 24) {
		// index = index - 16;
		// for (CtSettingBean bean : ctSettingBeans) {
		// boolean boo = false;
		// if (getTargetName(
		// (String) dataSourceListBlock2.get(i - 16).get(
		// "item_image")).equals(
		// bean.getTargetName())) {
		// boo = true;
		// if (bean.isUseDaultSetting()) {
		//
		// if (((ParameterSettingActivity) getActivity()).defaultBaselineBoo) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "C" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "C" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "Manual",
		// ((ParameterSettingActivity) getActivity()).defaultStart,
		// ((ParameterSettingActivity) getActivity()).defaultEnd));
		// }
		//
		// } else {
		// if (bean.isAutoBaseLine()) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "C" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "C" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "Manual", "AUTO", "AUTO"));
		// }
		// }
		//
		// } else {
		// if ("".equals(getTargetName((String) dataSourceListBlock2
		// .get(i - 16).get("item_image")))) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "C" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16).get(
		// "item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// }
		//
		// }
		// }
		// } else {
		// index = index - 24;
		// for (CtSettingBean bean : ctSettingBeans) {
		// boolean boo = false;
		// if (getTargetName(
		// (String) dataSourceListBlock2.get(i - 16).get(
		// "item_image")).equals(
		// bean.getTargetName())) {
		// boo = true;
		// if (bean.isUseDaultSetting()) {
		//
		// if (((ParameterSettingActivity) getActivity()).defaultBaselineBoo) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "D" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "D" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "Manual",
		// ((ParameterSettingActivity) getActivity()).defaultStart,
		// ((ParameterSettingActivity) getActivity()).defaultEnd));
		// }
		//
		// } else {
		// if (bean.isAutoBaseLine()) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "D" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// } else {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "D" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16)
		// .get("item_image")),
		// "Manual",
		// bean.getBaselineStart(),
		// bean.getBaselineEnd()));
		// }
		// }
		//
		// } else {
		// if ("".equals(getTargetName((String) dataSourceListBlock2
		// .get(i - 16).get("item_image")))) {
		// advancedSettingBeans
		// .add(new AdvancedSettingBean(
		// "D" + index,
		// getTargetName((String) dataSourceListBlock2
		// .get(i - 16).get(
		// "item_image")),
		// "AUTO", "AUTO", "AUTO"));
		// }
		//
		// }
		//
		// }
		// }
		//
		// }
		// }

		// 获取

		if (contextString.toString().contains("advancedSettingBeans")) {

			String advanceContextString = contextString.substring(
					contextString.indexOf(",,advancedSettingBeans,") + 23,
					contextString.length());

			// advancedSettingBeans
			int index = 0;
			while (advanceContextString.indexOf("well:", index) > 0) {

				// well:A1
				// targetName:target
				// baseLineName:AUTO
				// baselineStart:AUTO
				// baselineEnd:AUTO
				// useCTSetingBoo:true
				// autoBaselineBoolean:true
				String well = advanceContextString.substring(
						advanceContextString.indexOf("well:", index) + 5,
						advanceContextString.indexOf(",targetName:", index));
				String targetName = advanceContextString
						.substring(advanceContextString.indexOf("targetName:",
								index) + 11, advanceContextString.indexOf(
								",baseLineName:", index));
				String baseLineName = advanceContextString
						.substring(advanceContextString.indexOf(
								"baseLineName:", index) + 13,
								advanceContextString.indexOf(",baselineStart:",
										index));
				String baselineStart = advanceContextString
						.substring(advanceContextString.indexOf(
								"baselineStart:", index) + 14,
								advanceContextString.indexOf(",baselineEnd:",
										index));
				String baselineEnd = advanceContextString
						.substring(advanceContextString.indexOf("baselineEnd:",
								index) + 12, advanceContextString.indexOf(
								",useCTSetingBoo:", index));
				Boolean useCTSetingBoo = Boolean
						.parseBoolean(advanceContextString.substring(
								advanceContextString.indexOf("useCTSetingBoo:",
										index) + 15,
								advanceContextString.indexOf(
										",autoBaselineBoolean:", index)));

				int nextIndex = advanceContextString.indexOf(
						"autoBaselineBoolean:", index) + 20;
				if (advanceContextString.indexOf(",well:", nextIndex) < 0) {
					Boolean autoBaselineBoolean = Boolean
							.parseBoolean(advanceContextString.substring(
									advanceContextString.indexOf(
											"autoBaselineBoolean:", index) + 20,
									advanceContextString.length() - 1));

					for (AdvancedSettingBean bean : advancedSettingBeans) {
						if (bean.getWell().equals(well)) {
							bean.setTargetName(targetName);
							bean.setBaseLine(baseLineName);
							bean.setBaselineStart(baselineStart);
							bean.setBaselineEndString(baselineEnd);
							bean.setUseCTSetingBoo(useCTSetingBoo);
							bean.setAutoBaselineBoolean(autoBaselineBoolean);

						}
					}

				} else {
					Boolean autoBaselineBoolean = Boolean
							.parseBoolean(advanceContextString.substring(
									advanceContextString.indexOf(
											"autoBaselineBoolean:", index) + 20,
									advanceContextString.indexOf(",well:",
											nextIndex)));

					// for (AdvancedSettingBean bean : advancedSettingBeans) {
					// if (bean.getWell().equals(well)) {
					// bean.setTargetName(targetName);
					// bean.setBaseLine(baseLineName);
					// bean.setBaselineStart(baselineStart);
					// bean.setBaselineEndString(baselineEnd);
					// bean.setUseCTSetingBoo(useCTSetingBoo);
					// bean.setAutoBaselineBoolean(autoBaselineBoolean);
					//
					// }
					// }
					advancedSettingBeans.add(new AdvancedSettingBean(well,
							targetName, baseLineName, baselineStart,
							baselineEnd, useCTSetingBoo, autoBaselineBoolean));

				}

				index = advanceContextString.indexOf("autoBaselineBoolean:",
						index) + 21;

			}

		}

	}

	private void getLayoutone() {
		// layoutOne的数据解析
		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		// LogUtil.e(contextString.indexOf(",Aisle") + 7);
		// LogUtil.e(contextString.indexOf(",Color"));

		int index = 0;
		while (!(contextString.indexOf("Aisle", index) <= 0)) {

			// Aisle:
			String aisle;
			aisle = contextString.substring(
					contextString.indexOf(",Aisle", index) + 7,

					contextString.indexOf(",Color", index));
			// LogUtil.e(aisle);

			// Color
			String color;
			color = contextString.substring(
					contextString.indexOf(",Color", index) + 7,

					contextString.indexOf(",Target", index));
			// LogUtil.e(color);

			// Target
			String target;
			target = contextString.substring(
					contextString.indexOf(",Target", index) + 8,

					contextString.indexOf(",Dyes", index));

			// LogUtil.e(target);

			int nextIndex = contextString.indexOf(",Aisle", index) + 7;

			// Dyes
			String dyes;
			if (contextString.indexOf(",Aisle", nextIndex) < 0) {

				dyes = contextString.substring(
						contextString.indexOf(",Dyes", index) + 6,
						contextString.indexOf(",,dataSourceListBlock1", index));

				// LogUtil.e(dyes);
			} else {

				dyes = contextString.substring(
						contextString.indexOf(",Dyes", index) + 6,

						contextString.indexOf(",Aisle", nextIndex));
				// LogUtil.e(dyes);
			}

			index = contextString.indexOf(",Dyes", index) + 5;

			activityLayoutTableBeans.add(new LayoutTableBean(false, Integer
					.parseInt(aisle.trim()), Integer.parseInt(color.trim()),
					target, dyes));
		}

	}

	private void getDragView() {
		int index = 0;

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(
					contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(
					contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14,
					contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(
						contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (i == 15) {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",,dataSourceListBlock2", index))
						.trim();

			} else {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",item_image:", nextIndex))
						.trim();
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock1.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(
					contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(
					contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14,
					contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(
						contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (contextString.indexOf("item_image:", nextIndex) < 0) {
				if ("Absolute Quantitation"
						.equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
						| "绝对定量".equals(SharedPreferencesUtils.get(getActivity(),
								BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {
					item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",,cameraSet", index)).trim();

				} else {
					item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",,endogenousControl", index)).trim();

				}

			} else {
				if (i == 15) {

					// TODO 最后一位不出来颜色bug在这以后再改
					if ("Absolute Quantitation"
							.equals(SharedPreferencesUtils.get(getActivity(),
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
							| "绝对定量".equals(SharedPreferencesUtils.get(getActivity(),
									BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {
						item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
								contextString.indexOf(",,cameraSet", index)).trim();
						
					}else {
						item_type = contextString.substring(contextString.indexOf("item_type:", index) + 10,
								contextString.indexOf(",,endogenousControl", index)).trim();

					}
					// ByAlert.alert(contextString.substring(
					// contextString.indexOf("item_type:", index) + 10,
					// contextString.length()-1));
				} else {
					item_type = contextString.substring(
							contextString.indexOf("item_type:", index) + 10,
							contextString.indexOf(",item_image:", nextIndex))
							.trim();
				}
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock2.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		Gson gson = new Gson();
		String json = "";
		json = (String) SharedPreferencesUtils
				.get(getActivity(),
						"positionsArrayList", "");
		Type type = new TypeToken<HashSet<Integer>>() {
		}.getType();
		HashSet<Integer> positionsArrayList = new HashSet<Integer>();
		if (TextUtils.isEmpty(json)) {
		
		}else {
			positionsArrayList = gson.fromJson(json, type);
		}

		if (positionsArrayList != null) {
			for (int i : positionsArrayList) {
				if (i < 16) {
					HashMap<String, Object> hashMap = new HashMap<String, Object>();
					hashMap.put("item_image", "");
					hashMap.put("item_text", "");
					hashMap.put("item_selected", false);

					hashMap.put("item_aisle", 0);
					hashMap.put("item_type", "null");
					dataSourceListBlock1.set(i, hashMap);
				} else {
					HashMap<String, Object> hashMap = new HashMap<String, Object>();
					hashMap.put("item_image", "");
					hashMap.put("item_text", "");
					hashMap.put("item_selected", false);

					hashMap.put("item_aisle", 0);
					hashMap.put("item_type", "null");
					dataSourceListBlock2.set(i - 16, hashMap);
				}
			}
		}


	}

	private void getInfo() {
		contextString = new StringBuffer();
		folderName = SharedPreferencesUtils.get(getActivity(),
				BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "";
		fileName = SharedPreferencesUtils.get(getActivity(),
				BaseApplication.FILEMANGER_PREPAREFILENAME, "") + "";

		String path = appFilePath + "/" + folderName;

		File file = new File(path + "/" + fileName);
		
		FileInputStream in =null;
		BufferedReader reader=null;
		contextString=new StringBuffer();
		try {
			in =new FileInputStream(file);
			reader=new BufferedReader(new InputStreamReader(in));
			String line ="";
			while((line =reader.readLine())!=null){
				contextString.append(line);
				contextString.append(",");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(reader != null){
				try {
					reader.close();
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
		}
		
		
//		BufferedReader reader = null;
//		contextString=new StringBuffer();
//		System.gc();
//		try {
//			System.out.println("以行为单位读取文件内容，一次读一整行:");
//			reader = new BufferedReader(new FileReader(file));
//			String tempString = null;
//			int line = 1;
//			// 一次读入一行，直到读入null为文件结束
//			while ((tempString = reader.readLine()) != null) {
//				// 显示行号
//				// System.out.println("line " + line + ": " + tempString);
//				// Log.e("--", tempString);
//				contextString.append(tempString);
//				contextString.append(",");
//				line++;
//			}
//			reader.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (reader != null) {
//				try {
//					reader.close();
//					// LogUtil.e("!!", contextString + "");
//
//				} catch (IOException e1) {
//				}
//			}
//		}

		int index = 0;
		// 上面解析
		while (!(contextString.indexOf("steptType:", index) <= 0)) {

			// steptType:
			String steptType;
			steptType = contextString.substring(
					contextString.indexOf("steptType:", index) + 10,

					contextString.indexOf(",temperature:", index));

			// LogUtil.e(steptType);

			// temperature
			String temperature;
			temperature = contextString.substring(
					contextString.indexOf(",temperature:", index) + 13,

					contextString.indexOf(",time:", index));

			// LogUtil.e(temperature);
			// time
			String time;
			time = contextString.substring(
					contextString.indexOf(",time:", index) + 6,

					contextString.indexOf(",goTo:", index));
			// LogUtil.e(time);

			// goTo
			String goTo;
			goTo = contextString.substring(
					contextString.indexOf(",goTo:", index) + 6,

					contextString.indexOf(",Repititions:", index));
			// LogUtil.e(goTo);
			// Repititions
			String repititions;
			repititions = contextString.substring(
					contextString.indexOf(",Repititions:", index) + 13,

					contextString.indexOf(",deltaT:", index));
			// LogUtil.e(repititions);
			// deltaT
			String deltaT;
			deltaT = contextString.substring(
					contextString.indexOf(",deltaT:", index) + 8,

					contextString.indexOf(",rightSelect:", index));
			// LogUtil.e(deltaT);

			int nextIndex = contextString.indexOf("steptType:", index) + 10;

			// rightSelect
			String rightSelect;

			if (contextString.indexOf(",steptType:", nextIndex) < 0) {
				rightSelect = contextString.substring(
						contextString.indexOf(",rightSelect:", index) + 13,
						contextString.indexOf(",,pointMap", index));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}

			} else {
				rightSelect = contextString.substring(
						contextString.indexOf(",rightSelect:", index) + 13,

						contextString.indexOf(",steptType:", nextIndex));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}
			}
			// LogUtil.e(rightSelect);
			index = contextString.indexOf(",rightSelect:", index) + 13;

			activityMethodBeans.add(new MethodBean(steptType.trim(),
					temperature.trim(), time.trim(), goTo.trim(), repititions
							.trim(), deltaT.trim()));
		}
		// 获取重复次数

		int stepNum = Integer.parseInt(contextString.substring(
				contextString.indexOf(",readDataString: ") + 17,
				contextString.indexOf(",,Methods")).trim());
		repititionsGet(stepNum);
		pop_end_edit.setText(repititions+"");

	}

	private void repititionsGet(int stepNum) {
		// 先找出拍照的位置
		int cameraStep = stepNum-1;
//		for (MethodBean bean : activityMethodBeans) {
//			if (bean.getRightSelect()) {
//				break;
//			}
//			cameraStep++;
//		}
		ArrayList<ArrayList<Integer>> ranges = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer> littleRange;
		int startStep = 0;
		for (MethodBean bean : activityMethodBeans) {
			if (!TextUtils.isEmpty(bean.getGoTo())) {
				littleRange = new ArrayList<Integer>();
				littleRange.add(startStep);
				littleRange.add(Integer.parseInt(bean.getGoTo())-1);
				ranges.add(littleRange);
			}
			startStep++;
		}

		// 判断有没有跳转
		if (ranges.size() == 0) {
			repititions = 1;
			return;
		} else {
			int sum = 1;
			for (ArrayList<Integer> little : ranges) {
				if (cameraStep <= little.get(0)) {
					if (cameraStep >= little.get(1)) {
						sum = sum * Integer.parseInt(activityMethodBeans.get(little.get(0)).getRepititions());
					}
				}
			}
			repititions = sum;
			return;
		}

	}

	@Override
	protected void dataView() {
		// TODO Auto-generated method stub

		advance_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				show_position.setText("" + arg2);
			}
		});
		if(pop_threshold_check.isChecked()){

			setNoFocus(pop_rel);
			setNoFocus(pop_baseline_check);
			setNoFocus(pop_start_add);
			setNoFocus(pop_start_reduce);
			setNoFocus(pop_end_add);
			setNoFocus(pop_end_reduce);
			setNoFocus(pop_end_edit);
			setNoFocus(pop_start_edit);
		
		}else {

			setOnFocus(pop_rel);
			setOnFocus(pop_baseline_check);
			setNoFocus(pop_start_add);
			setNoFocus(pop_start_reduce);
			setNoFocus(pop_end_add);
			setNoFocus(pop_end_reduce);
			setNoFocus(pop_end_edit);
			setNoFocus(pop_start_edit);
		
		}
		if(pop_baseline_check.isChecked()){

			setNoFocus(pop_start_add);
			setNoFocus(pop_start_reduce);
			setNoFocus(pop_end_add);
			setNoFocus(pop_end_reduce);
			setNoFocus(pop_end_edit);
			setNoFocus(pop_start_edit);
		
		}else {

			setOnFocus(pop_start_add);
			setOnFocus(pop_start_reduce);
			setOnFocus(pop_end_add);
			setOnFocus(pop_end_reduce);
			setOnFocus(pop_end_edit);
			setOnFocus(pop_start_edit);
		
		}
		pop_threshold_check
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						// TODO Auto-generated method stub
						if (isChecked) {
							setNoFocus(pop_rel);
							setNoFocus(pop_baseline_check);
							setNoFocus(pop_start_add);
							setNoFocus(pop_start_reduce);
							setNoFocus(pop_end_add);
							setNoFocus(pop_end_reduce);
							setNoFocus(pop_end_edit);
							setNoFocus(pop_start_edit);
							pop_baseline_check.setChecked(true);
						} else {
							setOnFocus(pop_rel);
							setOnFocus(pop_baseline_check);
							setNoFocus(pop_start_add);
							setNoFocus(pop_start_reduce);
							setNoFocus(pop_end_add);
							setNoFocus(pop_end_reduce);
							setNoFocus(pop_end_edit);
							setNoFocus(pop_start_edit);
						}
					}
				});
		pop_baseline_check
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						// TODO Auto-generated method stub
						if (isChecked) {
							setNoFocus(pop_start_add);
							setNoFocus(pop_start_reduce);
							setNoFocus(pop_end_add);
							setNoFocus(pop_end_reduce);
							setNoFocus(pop_end_edit);
							setNoFocus(pop_start_edit);
						} else {
							setOnFocus(pop_start_add);
							setOnFocus(pop_start_reduce);
							setOnFocus(pop_end_add);
							setOnFocus(pop_end_reduce);
							setOnFocus(pop_end_edit);
							setOnFocus(pop_start_edit);
//							pop_start_add.setAlpha(1f);
//							pop_start_reduce.setAlpha(1f);
//							pop_end_add.setAlpha(1f);
//							pop_end_reduce.setAlpha(1f);
//							pop_end_edit.setAlpha(1f);
//							pop_start_add.setAlpha(1f);
						}
					}
				});
		pop_start_add.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					double d = Double.parseDouble(pop_start_edit.getText() + "");
					d++;
					pop_start_edit.setText(d + "");
				} catch (Exception e) {
					// TODO: handle exception

				}
			}
		});
		pop_start_reduce.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					double d = Double.parseDouble(pop_start_edit.getText() + "");
					d--;
					pop_start_edit.setText(d + "");
				} catch (Exception e) {
					// TODO: handle exception

				}
			}
		});
		pop_end_add.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					double d = Double.parseDouble(pop_end_edit.getText() + "");
					d++;
					pop_end_edit.setText(d + "");
				} catch (Exception e) {
					// TODO: handle exception

				}
			}
		});
		pop_end_reduce.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					double d = Double.parseDouble(pop_end_edit.getText() + "");
					d--;
					pop_end_edit.setText(d + "");
				} catch (Exception e) {
					// TODO: handle exception

				}
			}
		});
	}

	private void setNoFocus(View view) {
		view.setAlpha(0.5f);
		view.setEnabled(false);
		view.setClickable(false);
	}

	private void setOnFocus(View view) {
		view.setAlpha(1.0f);
		view.setEnabled(true);
		view.setClickable(true);
	}

	private class AdvanceAdapter extends BaseAdapter {
		ArrayList<AdvancedSettingBean> advancedSettingBeans;

		public AdvanceAdapter(
				ArrayList<AdvancedSettingBean> advancedSettingBeans) {
			super();
			this.advancedSettingBeans = advancedSettingBeans;
		}

		@Override
		public int getCount() {
			return advancedSettingBeans.size();
		}

		@Override
		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			// TODO Auto-generated method stub
			viewHolder holder = null;
			if (convertView == null) {
				holder = new viewHolder();
				convertView = LayoutInflater.from(getActivity()).inflate(
						R.layout.item_ct_fragment, null);
				holder.well_tv = (TextView) convertView
						.findViewById(R.id.well_tv);
				convertView.setTag(holder);
				holder.traget_tv = (TextView) convertView
						.findViewById(R.id.traget_tv);
				holder.threshold_tv = (TextView) convertView
						.findViewById(R.id.threshold_tv);
				holder.start_tv = (TextView) convertView
						.findViewById(R.id.start_tv);
				holder.end_tv = (TextView) convertView
						.findViewById(R.id.end_tv);
				holder.line = (LinearLayout) convertView
						.findViewById(R.id.line);
			} else {
				holder = (viewHolder) convertView.getTag();
			}
			holder.well_tv.setVisibility(View.VISIBLE);

			holder.well_tv
					.setText(advancedSettingBeans.get(position).getWell());
			holder.traget_tv.setText(advancedSettingBeans.get(position)
					.getTargetName());
			// holder.threshold_tv.setText(advancedSettingBeans.get(position)
			// .getBaseLine());

			// if (advancedSettingBeans.get(position).getUseCTSetingBoo()) {
			// // true ct页面的数据
			// // 先判断是什么的target
			// for (int i = 0; i < ctSettingBeans.size(); i++) {
			// if (advancedSettingBeans.get(position).getTargetName()
			// .equals(ctSettingBeans.get(i).getTargetName())) {
			// if (ctSettingBeans.get(i).isAutoBaseLine()) {
			// holder.threshold_tv.setText("AUTO");
			// advancedSettingBeans.get(position).setThreshold(
			// "AUTO");
			// } else {
			// holder.threshold_tv.setText("Manual");
			// advancedSettingBeans.get(position).setThreshold(
			// "Manual");
			// }
			// }
			// }
			//
			// } else {
			// // false
			// // 判断这个页面的autobaseline是否选中
			// if (pop_baseline_check.isChecked()) {
			// holder.threshold_tv.setText("AUTO");
			// advancedSettingBeans.get(position).setThreshold("AUTO");
			// } else {
			// holder.threshold_tv.setText("Manual");
			// advancedSettingBeans.get(position).setThreshold("Manual");
			// holder.start_tv.setText(pop_start_edit.getText() + "");
			// holder.end_tv.setText(pop_end_edit.getText() + "");
			// advancedSettingBeans.get(position).setBaselineStart(
			// pop_start_edit.getText() + "");
			// advancedSettingBeans.get(position).setBaselineEndString(
			// pop_end_edit.getText() + "");
			// }
			//
			// }

			holder.threshold_tv.setText(advancedSettingBeans.get(position)
					.getThreshold());

			holder.start_tv.setText(advancedSettingBeans.get(position)
					.getBaselineStart());
			holder.end_tv.setText(advancedSettingBeans.get(position)
					.getBaselineEndString());

			if (advancedSettingBeans.get(position).getSelected()) {
				holder.line.setBackground(getResources().getDrawable(
						R.color.selected_color));
			} else {
				holder.line.setBackground(getResources().getDrawable(
						R.color.white));
			}
			holder.line.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					for (AdvancedSettingBean bean : advancedSettingBeans) {
						bean.setSelected(false);
					}
					advancedSettingBeans.get(position).setSelected(true);
					adapter.notifyDataSetChanged();

					pop_threshold_check.setChecked(advancedSettingBeans.get(
							position).getUseCTSetingBoo());
					pop_baseline_check.setChecked(advancedSettingBeans.get(
							position).getAutoBaselineBoolean());

				}
			});

			return convertView;
		}
	}

	private class viewHolder {
		TextView well_tv;
		TextView traget_tv;
		TextView threshold_tv;
		TextView start_tv;
		TextView end_tv;
		LinearLayout line;
	}

	private String getTargetName(String color) {
		for (int i = 0; i < activityLayoutTableBeans.size(); i++) {
			if (color.equals(activityLayoutTableBeans.get(i).getColor() + "")) {
				return activityLayoutTableBeans.get(i).getTarget();
			}
		}
		return "";
	}

	// 定义一个回调接口
	public interface CallBackValue {
		public void SendMessageValue(
				ArrayList<AdvancedSettingBean> advancedSettingBeans);
	}
}
